#define _CRT_SECURE_NO_WARNINGS

struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB)
{
    struct ListNode* cura = headA;
    struct ListNode* curb = headB;

    int sizea = 0;
    int sizeb = 0;

    while (cura->next)
    {
        sizea++;
        cura = cura->next;
    }
    while (curb->next)
    {
        sizeb++;
        curb = curb->next;
    }
    if (cura != curb)
        return NULL;
    int size = abs(sizea - sizeb);

    struct ListNode* LNode = headA;
    struct ListNode* SNode = headB;
    if (sizeb > sizea)
    {
        LNode = headB;
        SNode = headA;
    }

    while (size > 0)
    {
        size--;
        LNode = LNode->next;
    }
    while (LNode)
    {
        if (LNode == SNode)
            return LNode;
        LNode = LNode->next;
        SNode = SNode->next;
    }
    return NULL;
}